
--保留技能
local ui = class.panel.create([[textures\black32.blp]],(1920-500)/2,400,500,200)
ui:add_text('吞噬英雄技能',0,10,nil,30,12,5)
ui:set_level(99)
ui:hide()

local w1,h1 = 64,64
local x1 = 20
local y1 = 70
ui.buttons = {}

for a=1,7 do
    local panel = ui:add_button([[ui\ui_b0.tga]],x1 + (a-1)*65,y1,w1,h1)
    panel.icon = panel:add_panel('')
    panel.highlight1 = panel:add_highlight([[UI\Widgets\BattleNet\bnet-button01-highlight-mouse.blp]])
    panel.highlight1:hide()
    panel.index = a
    ui.buttons[a] = panel
end

ui.esc = ui:add_namebutton('取消',(ui.w-120)/2,ui.h-50,120,50,16)


function ui:update()
    local locplayer = ac.player.self
    local hero = locplayer.hero
    if hero==nil then
        return
    end
    for a,panel in ipairs(ui.buttons) do
        local skill = hero:find_skill(a,'英雄')
        panel.skill = skill
        if skill then
            panel.icon:set_normal_image(skill.art)
        else
            panel.icon:set_normal_image('')
        end
    end
end


function ui:on_button_clicked(button)
    local skill = button.skill
    if button.index and skill then
        ac.sync('同步-吞噬技能',button.index)
        self:hide()
    elseif button==self.esc then
        ac.sync('同步-吞噬技能',0)
        self:hide()
    end
end

function ui:on_button_mouse_enter(button)
    local skill = button.skill
    if skill then
        local tip = format_obj(skill,skill.tip)
        self:tooltip(skill.title or skill.name,tip)
    end
end


ac.game:event '玩家-显示吞噬技能'(function(_,player)
    player:set_data('吞噬技能',true)
    if player:is_self() then
        ui:update()
        ui:show()
    end
end)


ac.game:event '玩家-刷新UI'(function(_,player)
    if ui:is_show() then
        ui:update()
    end
end)